layui.use(['layer', 'element'], function () {
    var $ = layui.jquery, layer = layui.layer, element = layui.element;
    $(".myui-input").on("focus", function () {
        $(".myui-search").addClass("active-input")
    });
    $(".layui-custom-li .costom-section").on("click", function () {
        var id = $(this).attr("content");
        var title=$(this).children(".layui-custom-li-title").html();
        layer.open({
            title:title,
            type: 2,
            area: ['80%', '80%'],
            fixed: true, //不固定
            maxmin: true,
            content: '/uc/service/entity/'+id
        });
    });
    var lx = $("input[name='type']").val();
    var dx = $("input[name='fwdx']").val();
    var bm = $("input[name='zgbm']").val();
    var fwfs = $("input[name='fwfs']").val();
    $(".myui-fwbm").each(function (i, elem) {
        if ($(elem).attr("content") == bm) {
            $(elem).addClass("active-li")
        } else {
            $(elem).removeClass("active-li")
        }
    });
    $(".myui-fwlx").each(function (i, elem) {
        if ($(elem).attr("content") == lx) {
            $(elem).addClass("active-li")
        } else {
            $(elem).removeClass("active-li")
        }
    });
    $(".myui-fwdx").each(function (i, elem) {
        if ($(elem).attr("content") == dx) {
            $(elem).addClass("active-li")
        } else {
            $(elem).removeClass("active-li")
        }
    });
    $(".myui-fwfs").each(function (i, elem) {
        if ($(elem).attr("content") == fwfs) {
            $(elem).addClass("active-li")
        } else {
            $(elem).removeClass("active-li")
        }
    });
    $(".myui-input").on("blur", function () {
        $(".myui-search").removeClass("active-input")
    });
    $(".myui-fwbm").on("click", function () {
        var index = $(this).index() - 1;
        $("input[name='zgbm']").val($(this).attr("content"));
        $(".myui-fwbm").each(function (i, elem) {
            if (i == index) {
                $(elem).addClass("active-li")
            } else {
                $(elem).removeClass("active-li")
            }
        })
    });
    $(".myui-fwlx").on("click", function () {
        var index = $(this).index() - 1;
        $("input[name='type']").val($(this).attr("content"));
        $(".myui-fwlx").each(function (i, elem) {
            if (i == index) {
                $(elem).addClass("active-li")
            } else {
                $(elem).removeClass("active-li")
            }
        })
    });
    $(".myui-fwdx").on("click", function () {
        var index = $(this).index() - 1;
        $("input[name='fwdx']").val($(this).attr("content"));
        $(".myui-fwdx").each(function (i, elem) {
            if (i == index) {
                $(elem).addClass("active-li")
            } else {
                $(elem).removeClass("active-li")
            }
        })
    });
    $(".myui-fwfs").on("click", function () {
        var index = $(this).index() - 1;
        $("input[name='fwfs']").val($(this).attr("content"));
        $(".myui-fwfs").each(function (i, elem) {
            if (i == index) {
                $(elem).addClass("active-li")
            } else {
                $(elem).removeClass("active-li")
            }
        })
    });
    $(".myui-search-span,.myui-fwfs,.myui-fwdx,.myui-fwlx,.myui-fwbm").on("click", function () {
        AjaxObj()
    });
    document.onkeydown = function (e) {
        var ev = document.all ? window.event : e;
        if (ev.keyCode == 13) {
            AjaxObj()
        }
    };

    function AjaxObj() {
        $.ajax({
            type: "POST",
            url: "/uc/service/list/index",
            data: $("#serve-post").serialize(),
            async: false,
            dataType: "json",
            error: function (request) {
                console.log("Connection error")
            },
            success: function (data) {
                var html = "";
                if (null != data) {
                    var dataList = data.dataList;
                    if (null != dataList && dataList.length > 0) {
                        for (var i = 0; i < dataList.length; i++) {
                            html = html + "<div class='layui-custom-col3 layui-col-md3 layui-col-sm4 layui-col-xs12 layui-custom-li'><section class='costom-section' content='" + dataList[i].id + "'><div class='layui-custom-li-title'>" + dataList[i].name + "</div><div class='layui-custom-li-section'><img src='" + dataList[i].fwtp + "' class='layui-custom-image'/>" +
                            "<div class='layui-custom-article'><div class='layui-custom-li-title'>"+ dataList[i].fwlxFmt +"</div><div class='layui-custom-li-title'>"+ dataList[i].fwdxName +"</div>" +
                            "<div class='layui-custom-li-title'>"+ dataList[i].cjsfFmt +"</div></div></div>" +
                            "<footer class='layui-custom-pj'>";
                            var text="";//custom-li-hover
                            if(null==dataList[i].fwpj){
                                for (var j=0;j<5;j++){
                                    text=text+"<div class='custom-li'></div>";
                                }
                            }else {
                                var fwpj=dataList[i].fwpj;
                                for (var j=0;j<fwpj;j++){
                                    text=text+"<div class='custom-li custom-li-hover'></div>";
                                }
                                for (var k=0;k<(5-fwpj);j++){
                                    text=text+"<div class='custom-li'></div>";
                                }
                            }
                            html=html+text+"</footer></section></div>";
                        }
                    }
                }
                $(".custom-header1 .layui-row").html(html);
                $(".layui-custom-li .costom-section").on("click", function () {
                    var id = $(this).attr("content");
                    var title=$(this).children(".layui-custom-li-title").html();
                    layer.open({
                        title:title,
                        type: 2,
                        area: ['80%', '80%'],
                        fixed: true, //不固定
                        maxmin: true,
                        content: '/uc/service/entity/'+id
                    });
                });
            }
        })
    }
});
